/**
 * 
 */
package com.daviteq.ems.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.daviteq.dto.RoleUser;
import com.google.gson.annotations.SerializedName;


/**
 * Entity of User
 * 
 * @author thanhthi.tran
 * @date Apr 1, 2014
 * @since 0.0.1
 */
@Table(name = "user", indexes = {
        @Index(name = "user_email_idx", columnList = "email"),
        @Index(name = "user_status_idx", columnList = "status"),
        @Index(name = "user_mobile_idx", columnList = "mobile")
})
public class UserEntity {

    @Transient
    public final static String USERNAME = "username";

    @Transient
    public final static String PASSWORD = "password";

    @Transient
    public final static String FIRST_NAME = "first_name";

    @Transient
    public final static String LAST_NAME = "last_name";
    @Transient
    public final static String GENDER = "gender";
    @Transient
    public final static String BIRTHDAY = "birthday";
    @Transient
    public final static String EMAIL = "email";
    @Transient
    public final static String MOBILE = "mobile";

    @Transient
    public final static String LAST_LOGIN = "last_login";
    @Transient
    public final static String FAILED_LOGIN_ATTEMPTS = "failed_login_attempts";
    @Transient
    public final static String CREATED_DATE = "created_date";
    @Transient
    public final static String LAST_UPDATED = "last_updated";
    @Transient
    public final static String STATUS = "status";

    @Id
    @Column(name = USERNAME)
    @SerializedName("username")
    private String username;

    @Column(name = PASSWORD)
    private String password;

    @Column(name = FIRST_NAME)
    private String firstName;

    @Column(name = LAST_NAME)
    private String lastName;

    @Column(name = GENDER)
    private String gender;

    @Column(name = BIRTHDAY)
    private String birthday;

    @Column(name = EMAIL)
    private String email;

    @Column(name = MOBILE)
    private String mobile;

    @Column(name = LAST_LOGIN)
    private String lastLogin;

    @Column(name = FAILED_LOGIN_ATTEMPTS)
    private int failedLoginAttempts;

    @Column(name = CREATED_DATE)
    private String createdDate;

    @Column(name = LAST_UPDATED)
    private String lastUpdated;

    @Column(name = STATUS)
    private String status;

    // extend
    public String getFullName() {
        StringBuilder fullName = new StringBuilder().append(firstName)
                .append(" ").append(lastName);
        return fullName.toString();
    }

    public String getUsername() {
        if (username != null && username.length() != 0) {
            username = username.toLowerCase();
        }
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getEmail() {
        if (email != null && email.length() != 0) {
            email = email.toLowerCase();
        }
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(String lastLogin) {
        this.lastLogin = lastLogin;
    }

    public int getFailedLoginAttempts() {
        return failedLoginAttempts;
    }

    public void setFailedLoginAttempts(int failedLoginAttempts) {
        this.failedLoginAttempts = failedLoginAttempts;
    }

    public String getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(String createdDate) {
        this.createdDate = createdDate;
    }

    public String getLastUpdated() {
        return lastUpdated;
    }

    public void setLastUpdated(String lastUpdated) {
        this.lastUpdated = lastUpdated;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
   
  
	@Override
    public String toString() {
    	// TODO Auto-generated method stub
    	return this.username;
    }
}
